<?php
require_once 'class.database.php';

class DetailKartuDao {
	public function cekDetail($idKartu){
        $db = Database::getInstance();
        $con = $db->getConnection(1);

        $query = "SELECT * FROM t_det_kartu WHERE idKartu='$idKartu'";

        $result = $con->prepare($query);
        $result->execute();

        if ($result->rowCount() >= 1) {
            return true;
        }

        return false;
    }

    public function getDetail($idCuti){
        $db = Database::getInstance();
        $con = $db->getConnection(1);

        $query = "SELECT * FROM t_det_kartu WHERE idCuti='$idCuti'";

        $result = $con->prepare($query);
        $result->execute();

        if ($result->rowCount() == 1) {
            return $result->fetch();
        }

        return false;
    }

    public function getAllDetail($idKartu){
        $db = Database::getInstance();
        $con = $db->getConnection(1);

        $query = "SELECT * FROM t_det_kartu WHERE idKartu='$idKartu'";

        $result = $con->prepare($query);
        $result->execute();

        if ($result->rowCount() >= 1) {
            return $result->fetchAll();
        }

        return false;
    }

    public function createKartu(DetailKartu $detail){
        $db= Database::getInstance();
        $con=$db->getConnection(1);

        $tglPengartuan=date('Y-m-d');
        $query="INSERT INTO t_det_kartu(idKartu,idCuti,idBatal,nomorSurat,tglSurat,jmlCuti,tglPengartuan,jmlCutiBatal) ";
        $query.=" VALUES('$detail->idKartu','$detail->idCuti','$detail->idBatal','$detail->nomorSurat','$detail->tglSurat','$detail->jmlCuti','$tglPengartuan','$detail->jmlCutiBatal')";

        //print_r($query);
        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()==1){
            return true;
        }

        return false;
    }

    public function updateKartu(DetailKartu $detail){
        $db= Database::getInstance();
        $con=$db->getConnection(1);

        $tglPengartuan=date('Y-m-d');
        $query="UPDATE t_det_kartu SET nomorSurat='$detail->nomorSurat',tglSurat='$detail->tglSurat' WHERE id='$detail->id'";

        //print_r($query);
        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()==1){
            return true;
        }

        return false;
    }
}

class DetailKartu {
	var $id;
	var $idKartu;
	var $idCuti;
    var $idBatal;
	var $nomorSurat;
	var $tglSurat;
    var $tglPengartuan;
    var $jmlCuti;
    var $jmlCutiBatal;

}

?>